package towerDefense.units;

import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.util.LinkedList;


public class LifeSprite extends PathingSprite implements IAlive
{
    private double myMaxHP;
    private double myCurrentHP;


    public LifeSprite ()
    {
        super();
    }


    public LifeSprite (BufferedImage image,
                       double r,
                       double spd,
                       LinkedList<Point2D> path,
                       double maxHP)
    {
        super(image, r, spd, path);
        myMaxHP = maxHP;
        myCurrentHP = maxHP;
    }


    public LifeSprite (BufferedImage image,
                       double x,
                       double y,
                       double r,
                       double spd,
                       LinkedList<Point2D> path,
                       double maxHP)
    {
        super(image, x, y, r, spd, path);
        myMaxHP = maxHP;
        myCurrentHP = maxHP;
    }


    public LifeSprite (double x,
                       double y,
                       double r,
                       LinkedList<Point2D> path,
                       double maxHP)
    {
        super(x, y, r, path);
        myMaxHP = maxHP;
        myCurrentHP = maxHP;
    }


    public void setMaxHP (double myMaxHP)
    {
        this.myMaxHP = myMaxHP;
    }


    public double getMaxHP ()
    {
        return myMaxHP;
    }


    public void setCurrentHP (double myCurrentHP)
    {
        this.myCurrentHP = myCurrentHP;
    }


    public double getCurrentHP ()
    {
        return myCurrentHP;
    }


    public double decreaseHP (double change)
    {
        myCurrentHP -= change;
        if (myCurrentHP < 0) myCurrentHP = 0;
        return myCurrentHP;
    }


    public double increaseHP (double change)
    {
        myCurrentHP = +change;
        return myCurrentHP;
    }


    //TODO implement cool death/life stuff
    @Override
    public void die ()
    {
        this.setActive(false);
        //play a sound
        //do an animation?
    }


    @Override
    public void comeToLife ()
    {
        this.setActive(true);
        //play a sound
        //do an animation?
    }


    @Override
    public void update (long elapsedTime)
    {
        super.update(elapsedTime);
        if (myCurrentHP <= 0) this.die();
        else if (myCurrentHP > 0 && !this.isActive() && this.isOnScreen()) this.comeToLife();
    }
}
